#! /bin/shell

#======================================================================
# 停止hdfs shell脚本
# 通过项目名称查找到PID
# 然后kill -9 pid
#
# author: wangzhichao
#======================================================================


# 组件 DataNode
DataNode="DataNode"

PID_DataNode=$(ps -ef | grep "${DataNode}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID_DataNode" ]]
then
    echo ${DataNode} is already stopped
else
    echo kill  ${PID_DataNode}
    kill -9 ${PID_DataNode}
    echo ${DataNode} stopped successfully
fi

# 组件 NameNode
NameNode="NameNode"

PID_NameNode=$(ps -ef | grep "${NameNode}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID_NameNode" ]]
then
    echo ${NameNode} is already stopped
else
    echo kill  ${PID_NameNode}
    kill -9 ${PID_NameNode}
    echo ${NameNode} stopped successfully
fi

# 组件 JournalNode
JournalNode="JournalNode"

PID_JournalNode=$(ps -ef | grep "${JournalNode}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID_JournalNode" ]]
then
    echo ${JournalNode} is already stopped
else
    echo kill  ${PID_JournalNode}
    kill -9 ${PID_JournalNode}
    echo ${JournalNode} stopped successfully
fi

# 组件 SecondaryNameNode
SecondaryNameNode="SecondaryNameNode"

PID_SecondaryNameNode=$(ps -ef | grep "${SecondaryNameNode}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID_SecondaryNameNode" ]]
then
    echo ${SecondaryNameNode} is already stopped
else
    echo kill  ${PID_SecondaryNameNode}
    kill -9 ${PID_SecondaryNameNode}
    echo ${SecondaryNameNode} stopped successfully
fi

echo OK